//
//  TFPageViewControllerContainerView.h
//  TFFoundation
//
//  Created by TFAppleWork-Summer on 2017/8/15.
//  Copyright © 2017年 TFAppleWork-Summer. All rights reserved.
//

#import <UIKit/UIKit.h>

@class TFPageViewControllerContainerView;

/**
 TFPageViewControllerContainerView数据源
 */
@protocol TFPageViewControllerContainerViewDataSource <NSObject>

@required
/**
 返回VC的个数
 
 @param pageViewControllerContainerView pageVC容器view
 @return vc的个数
 */
- (NSUInteger)numberOfViewControllersInPageViewControllerContainerView:(nonnull TFPageViewControllerContainerView *)pageViewControllerContainerView;

/**
 返回指定index的VC
 
 @param pageViewControllerContainerView pageVC容器view
 @param index 索引
 @return VC
 */
- (nonnull __kindof UIViewController *)pageViewControllerContainerView:(nonnull TFPageViewControllerContainerView *)pageViewControllerContainerView viewControllerForIndex:(NSUInteger)index;

@end

/**
 TFPageViewControllerContainerView代理
 */
@protocol TFPageViewControllerContainerViewDelegate <NSObject>

@optional;

/**
 滚动pageNode时的回调
 
 @param pageViewControllerContainerView pageVC容器view
 @param index 目标index
 @param percent 滚动的百分之几
 */
- (void)pageViewControllerContainerView:(nonnull TFPageViewControllerContainerView *)pageViewControllerContainerView
                      scrollTo:(NSInteger)index
                     byPercent:(CGFloat)percent;

/**
 pageView滚动到index时的回调
 
 @param pageViewControllerContainerView pageVC容器view
 @param index index
 */
- (void)pageViewControllerContainerView:(nonnull TFPageViewControllerContainerView *)pageViewControllerContainerView didSelectViewControllerAtIndex:(NSUInteger)index;

@end


/**
 容器View，用来装载VC的view，用法与tableView，collectionView类似
 */
@interface TFPageViewControllerContainerView : UIView

/**
 数据源
 */
@property (nonatomic, weak, nullable) id<TFPageViewControllerContainerViewDataSource> dataSource;

/**
 代理者
 */
@property (nonatomic, weak, nullable) id<TFPageViewControllerContainerViewDelegate> delegate;

/**
 *  当前页
 */
@property (nonatomic, assign, readonly)NSInteger currentPage;

/**
 滚动到某个viewcontroller

 @param index 索引
 @param animated 是否使用动画
 */
- (void)scrollToViewControllerAtIndex:(NSUInteger)index animated:(BOOL)animated;

/**
 根据索引获取viewcontroller

 @param index 索引
 @return UIViewController
 */
- (nonnull __kindof UIViewController *)viewControllerAtIndex:(NSUInteger)index;

/**
 刷新PageView，会让所有的VC都被释放，然后重新生成
 */
- (void)reloadData;

/**
 更新布局
 */
- (void)updateLayout;

/**
 增加指定index的VC到PageView里，需要事先修改dataSource，不会造成其他VC的释放和重建
 
 @param indexSet 指定indexSet
 */
- (void)insertViewControllersAtIndexes:(nonnull NSIndexSet*)indexSet;

/**
 删除指定index的VC，需要事先修改dataSource，不会造成其他VC的释放和重建
 
 @param indexSet 指定indexSet
 */
- (void)deleteViewControllerAtIndexes:(nonnull NSIndexSet*)indexSet ;

/**
 替换指定位置的VC，需要事先修改dataSource，不会造成其他VC的释放和重建
 
 @param indexSet 指定indexSet
 */
- (void)replaceViewControllerIndexes:(nonnull NSIndexSet*)indexSet;

@end
